package cn.sunxyz.idea.demo.proxy;

import cn.sunxyz.idea.demo.aspect.AbstractInvocationHandler;
import cn.sunxyz.idea.demo.aspect.Invocation;
import cn.sunxyz.idea.demo.aspect.InvocationHandler;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * Created by yangrd on 2017/5/25.
 */
class HandlerProxy implements Proxy {

    private InvocationHandler invocationHandler = new AbstractInvocationHandler() {
    };

    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        return invocationHandler.handlerInvocation(new Invocation(obj, method, args, proxy));
    }

    public HandlerProxy setInvocationHandler(InvocationHandler invocationHandler) {
        this.invocationHandler = invocationHandler;
        return this;
    }
}
